package com.dtw.ditouwang.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.NotifyBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;
import com.dtw.ditouwang.ui.OnItemClickListener;
import com.dtw.ditouwang.ui.more.EditorChoosePhotoDetailActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UserNotifyActivity extends BaseActivity implements OnItemClickListener {
    UserNotifyAdapter userNotifyAdapter;
    List<NotifyBean.DataBean> notifyBeanlIst = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notify_system);
        enableBack();
        setTitle("动态通知");
        userNotifyAdapter = new UserNotifyAdapter(notifyBeanlIst);
        userNotifyAdapter.setOnItemClickListener(this);
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true));
        recyclerView.setAdapter(userNotifyAdapter);

        webApi.getNotify(UserRepository.getInstance().getUserID(), 1).enqueue(new Callback<NotifyBean>() {
            @Override
            public void onResponse(Call<NotifyBean> call, Response<NotifyBean> response) {
                if (response.body().isResult()) {
                    notifyBeanlIst.clear();
                    notifyBeanlIst.addAll(response.body().getData());
                    userNotifyAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<NotifyBean> call, Throwable t) {

            }
        });
    }

    @Override
    public void onItemClick(int resID, int position, int state) {
        Intent intent=new Intent(this, EditorChoosePhotoDetailActivity.class);
        intent.putExtra(EditorChoosePhotoDetailActivity.KeyID,notifyBeanlIst.get(position).getArticle_id());
        startActivity(intent);
    }
}
